package com.dhcc.bpm.modules.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.api.entity.Externalcall;
import com.dhcc.bpm.modules.api.service.IExternalcallService;
import com.dhcc.bpm.modules.api.vo.ExternalcallVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName ExternalcallController
 * @Description  外部调用 控制器
 * @Author wjh
 * @Date 2020/2/25 13:14
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-api/externalcall")
@Api(value = "外部调用", tags = "接口")
public class ExternalcallController extends BladeController {

	private IExternalcallService externalcallService;

	/**
	 * @Description 外部调用详情
	 * @Author wjh
	 * @Date 10:10 2020/3/26
	 * @param externalcall
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.api.entity.Externalcall>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入externalcall")
	@Log(title = "外部调用详情", businessType = BusinessType.SELECT)
	@ApiLog("外部调用详情")
	public R<ExternalcallVO> detail(ExternalcallVO externalcall) {
		//Externalcall detail = externalcallService.getOne(Condition.getQueryWrapper(externalcall));
		ExternalcallVO detail = externalcallService.externalcallGetOne(externalcall);

		return R.data(detail);
	}

	/**
	 * @Description 查询外部调用信息
	 * @Author wjh
	 * @Date 10:10 2020/3/26
	 * @param externalcall
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.api.entity.Externalcall>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入externalcall")
	@Log(title = "查询外部调用信息", businessType = BusinessType.SELECT)
	@ApiLog("查询外部调用信息")
	public R<IPage<ExternalcallVO>> list(ExternalcallVO externalcall, Query query) {
		IPage<ExternalcallVO> pages = externalcallService.externalcallList(Condition.getPage(query), externalcall);
		return R.data(pages);
	}

	/**
	 * @Description 查询外部调用信息
	 * @Author wjh
	 * @Date 10:10 2020/3/26
	 * @param externalcall
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.api.vo.ExternalcallVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入externalcall")
	@Log(title = "查询外部调用信息", businessType = BusinessType.SELECT)
	@ApiLog("查询外部调用信息")
	public R<IPage<ExternalcallVO>> page(ExternalcallVO externalcall, Query query) {
		IPage<ExternalcallVO> pages = externalcallService.selectExternalcallPage(Condition.getPage(query), externalcall);
		return R.data(pages);
	}

	/**
	 * @Description 新增外部调用信息
	 * @Author wjh
	 * @Date 10:09 2020/3/26
	 * @param externalcall
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入externalcall")
	@Log(title = "新增外部调用信息", businessType = BusinessType.INSERT)
	@ApiLog("新增外部调用信息")
	public R save(@Valid @RequestBody Externalcall externalcall) {
		return R.status(externalcallService.save(externalcall));
	}

	/**
	 * @Description 修改
	 * @Author wjh
	 * @Date 10:09 2020/3/26
	 * @param externalcall
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入externalcall")
	@Log(title = "修改外部调用信息", businessType = BusinessType.UPDATE)
	@ApiLog("修改外部调用信息")
	public R update(@Valid @RequestBody Externalcall externalcall) {
		return R.status(externalcallService.updateById(externalcall));
	}

	/**
	 * @Description 新增或修改
	 * @Author wjh
	 * @Date 10:08 2020/3/26
	 * @param externalcall
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入externalcall")
	@Log(title = "新增或修改", businessType = BusinessType.INSERT)
	@ApiLog("新增或修改")
	public R submit(@Valid @RequestBody Externalcall externalcall) {
		return R.status(externalcallService.saveOrUpdate(externalcall));
	}


	/**
	 * @Description 删除
	 * @Author wjh
	 * @Date 10:08 2020/3/26
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	@Log(title = "删除", businessType = BusinessType.DELETE)
	@ApiLog("删除")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(externalcallService.removeByIds(Func.toLongList(ids)));
	}


}
